package demo5;

//接口是一个标准的规范
interface IFlying {
    //代表飞这个标准动作
    void fly();
    //接口中的方法默认是public abstract 修饰
    //属性是public static final 修饰的
}
interface ISwimming {
    void swim();
}
interface IRunning {
    void run();
}

abstract class Animal {
    private String name;
    private int age;

    public abstract void eat();

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public Animal(String name, int age) {
        this.name = name;
        this.age = age;
    }
}
//只能先继承再实现，在这只能先继承Animal类再实现Irunning,ISwimming接口
class Dog extends Animal implements IRunning,ISwimming{
    public Dog(String name,int age) {
        super(name,age);
    }
    @Override
    public void eat() {
        System.out.println(this.getName() + " 正在吃狗粮！");
    }

    @Override
    public void run() {
        System.out.println(this.getName() + " 正在用四条腿跑！");
    }

    @Override
    public void swim() {
        System.out.println(this.getName() + " 正在狗刨！");
    }
}
class Bird extends Animal implements IFlying {
    public Bird(String name, int age) {
        super(name, age);
    }

    @Override
    public void eat() {
        System.out.println(this.getName() + " 正在吃鸟！");
    }

    @Override
    public void fly() {
        System.out.println(this.getName() + " 正在用翅膀飞！");
    }
}

class Robot implements IRunning {
    @Override
    public void run() {
        System.out.println(" 机器人正在跑！");
    }
}
public class Test {
    public static void test1(Animal animal) {
        animal.eat();
    }
    public static void testFly(IFlying iFlying) {
        iFlying.fly();
    }

    public static void testRun(IRunning iRunning) {
        iRunning.run();
    }
    public static void testSwim(ISwimming iSwimming) {
        iSwimming.swim();
    }
    public static void main(String[] args) {
        testFly(new Bird("小鸟",1));
        testRun(new Dog("狗",3));
        testSwim(new Dog("狗",5));

        testRun(new Robot());
    }

    public static void main1(String[] args) {
        test1(new Bird("小鸟", 1));
        test1(new Dog("小狗", 2));
    }

}
interface A {
    void testA();
}
interface B {
    void testB();
}
//扩展功能
interface C extends A,B {
    void testC();
    //此时的C接口不仅有自己的接口同时包括A,B两个接口的功能
}
//代码：高内聚，低耦合是最好的
class D implements C {

    @Override
    public void testA() {

    }

    @Override
    public void testB() {

    }

    @Override
    public void testC() {

    }
}
